<?php
	include "../../public/commom/config.php";
	include "../lock1.php";
	include "../../public/commom/commom.php";
	include "../../public/commom/function.php";
	
	if($_POST){
//		echo "<pre>";
//			print_r($_POST);
//		echo "</pre>";
//		
//		echo "<pre>";
//			print_r($_FILES);
//		echo "</pre>";
		
		$name = $_POST["name"];
		$pice = $_POST["pice"];
		$inventory = $_POST["inventory"];
		$bid = $_POST["brand_id"];
		$sheif = $_POST["sheif"];
		
		//图片
		$imgsrc = $_FILES["img"]["tmp_name"];//获取图片临时路径
		$fname = $_FILES["img"]["name"];//获取图片名称
		$a = explode(".", $fname);//获取图片后缀名
		$ext = array_pop($a);//
		$dst = $uploadPath . time().mt_rand(). "." . $ext;//随机生成图片名称

		//图片上传成功
		if(move_uploaded_file($imgsrc, $dst)) {
			thumb($dst, 200, 200);//生成缩略图
			$img = basename($dst);//获取带后缀名的图片名称
		}
		
//		$img = basename($dst);//获取带后缀名的图片名称
//		move_uploaded_file($imgsrc, $dst);//执行上传图片
		
		$sql = "INSERT INTO shop (name, img, pice, inventory, brand_id, sheif) VALUES ('$name', '$img', '$pice', '$inventory', '$bid', '$sheif')";
			
		$result = mysqli_query($conn, $sql);
			
		mysqli_close($conn);
				
		header("Location: ./index.php");
	}
?>